package edu.bbu.commonproject.desktop.gui.controller.utils.dnd;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;

/**
 * The transferable file class, that implements the Transferable interface. 
 */
public class TransferableFile implements Transferable
{
	/**	The data flavor.*/
	public static DataFlavor fileFlavor = new DataFlavor(FileInformation.class, "A file Object");
	
	/**	The file information.*/
	private FileInformation fileInformation;

	/**
	 * The constructor.
	 * @param fileInformation the file information.
	 */
	public TransferableFile(FileInformation fileInformation)
	{
		this.fileInformation = fileInformation;
	}
	
	/**
	 * Getting the transfer data.
	 */
	public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException
	{
		if(flavor.equals(fileFlavor))
		{
			return fileInformation;
		}
		
		throw new UnsupportedFlavorException(flavor);
	}

	/**
	 * Getting the transfer data flavors.
	 */
	public DataFlavor[] getTransferDataFlavors()
	{
		return new DataFlavor[] {fileFlavor};
	}

	/**
	 * Getting that data flavor is supported or not.
	 */
	public boolean isDataFlavorSupported(DataFlavor flavor)
	{
		return flavor.equals(fileFlavor);
	}
}
